package com.sayyi.demo.test.business.controller;

import com.sayyi.demo.test.business.domain.UserInfo;
import com.sayyi.demo.test.business.service.UserInfoService;
import com.sayyi.demo.test.common.ResultBean;
import org.springframework.web.bind.annotation.*;

/**
 * @author xuchuang
 * date 2021/12/24 4:56 PM
 */
@RestController
@RequestMapping("/user")
public class UserInfoController {

    private UserInfoService userInfoService;

    public UserInfoController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    @PutMapping("/")
    public ResultBean<Long> save(@RequestBody UserInfo userInfo) {
        return ResultBean.success(userInfoService.save(userInfo));
    }
    @GetMapping("/{id}")
    public ResultBean<UserInfo> getById(@PathVariable("id") long id) {
        return ResultBean.success(userInfoService.getById(id));
    }
    @PostMapping("/")
    public ResultBean<Integer> updateById(@RequestBody UserInfo userInfo) {
        return ResultBean.success(userInfoService.updateById(userInfo));
    }
    @DeleteMapping("/{id}")
    public ResultBean<Integer> deleteById(@PathVariable("id") long id) {
        return ResultBean.success(userInfoService.deleteById(id));
    }
}
